package com.test.daily.leetcode.y2021.m10.day1015;

/**
 * @descriptions: countAndSay
 * @author: Tom
 * @date: 2021/10/15 上午 10:59
 * @version: 1.0
 */
public class Code01_CountAndSay {
    public static void main(String[] args) {
        System.out.println(countAndSay(12));
    }
    public static String countAndSay(int n){
        String str = "1";
        for(int i = 2; i <= n; i++){
            int start = 0;
            int pos = 0;
            StringBuilder sb = new StringBuilder();
            while(start < str.length()){
                while(pos < str.length() && str.charAt(start) == str.charAt(pos)){
                    pos++;
                }
                sb.append(pos - start).append(str.charAt(start));
                start = pos;
            }
            str = sb.toString();
        }
        return str;
    }
}
